package com.fary;

import com.fary.entity.School;
import com.fary.entity.Student;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.PropertyValue;

public class TestBeanWrapper {

	public static void main(String[] args) {
		//第一个学生
		BeanWrapper beanWrapper = new BeanWrapperImpl(new Student());
		PropertyValue pv = new PropertyValue("name","jack");
		PropertyValue pv1 = new PropertyValue("age",16);
		beanWrapper.setPropertyValue(pv);
		beanWrapper.setPropertyValue(pv1);
		Student student = (Student) beanWrapper.getWrappedInstance();
		System.out.println(student.getAge());
		System.out.println(student.getName());

		//第二个学生
		BeanWrapper beanWrapper2 = new BeanWrapperImpl(new Student());
		PropertyValue student2pv = new PropertyValue("name","Tom");
		PropertyValue student2pv2 = new PropertyValue("age",18);
		beanWrapper2.setPropertyValue(student2pv);
		beanWrapper2.setPropertyValue(student2pv2);
		Student student2 = (Student) beanWrapper2.getWrappedInstance();
		System.out.println(student2.getAge());
		System.out.println(student2.getName());

		//学校
		BeanWrapper schoolBeanWrapper3 = new BeanWrapperImpl(new School());
		PropertyValue schoolpv = new PropertyValue("schoolName","学校");
		Student[] st = {student,student2};
		schoolBeanWrapper3.setPropertyValue(schoolpv);
		schoolBeanWrapper3.setPropertyValue("students",st);
		schoolBeanWrapper3.setPropertyValue("students[1].age",20);
		School school = (School) schoolBeanWrapper3.getWrappedInstance();
		System.out.println(school);
	}

}
